Skip to main content

Overview

gdal2PLY.py converts Digital Elevation Models (DEMs) or Digital Terrain Models (DTMs) into 3D binary PLY (Polygon File Format) meshes suitable for 3D visualization and analysis.

Purpose

Create a 3D binary PLY format file from a GDAL-supported DEM/DTM raster, generating a triangulated mesh representation of terrain data. Original Author: Jake (posted on GIS StackExchange)
Modifications: Trent Hare, USGS
Source: GIS StackExchange

Installation Requirements

Recommended environment: Anaconda with GDAL installed via conda install gdal

Command Syntax

Parameters

input.tif
string
required
Input DEM/DTM file (any GDAL-supported raster format)
output.ply
string
required
Output PLY mesh file (binary format)

Usage Examples

Basic DEM to PLY Conversion

Complete Workflow with NoData Handling

NoData Handling

The current version does not automatically handle NoData values. Use the workflow below to prepare your data.

NoData Work-around Process

1. Identify Minimum Elevation
Example output: Computed Min/Max=-2790.594,5432.123 2. Set NoData to Safe Value Set GDAL NoData to the next round value below the minimum:
3. Generate PLY

How It Works

Vertex Array Creation

The script creates a vertex array from the raster (see gdal2PLY.py:69-78):

Triangle Index Generation

Creates triangulated faces from the grid (see gdal2PLY.py:81-93):

PLY File Structure

The output PLY file contains:
  • Header: Binary little/big-endian format specification
  • Vertex Properties: x, y, z coordinates (float32)
  • Face Definitions: Triangle vertex indices (int32)
  • Binary Data: Efficient storage of geometry

PLY Format Specification

Example PLY header generated:

Performance Considerations

Large DEMs: For very large DEMs, consider resampling before conversion to reduce mesh complexity and file size.

Optimization Tips

1. Resample Large Datasets
2. Clip to Area of Interest
3. Memory Considerations The script loads the entire raster into memory. For a 10000x10000 pixel DEM:
  • Vertices: ~1.2 GB
  • Triangles: ~2.4 GB
  • Total memory usage: ~3-4 GB

Viewing PLY Files

  • MeshLab: Open-source mesh processing tool
  • CloudCompare: Point cloud and mesh viewer
  • Blender: 3D modeling and visualization
  • ParaView: Scientific visualization

Load in MeshLab

PlateVertex2Obj

For converting PDS Shapemodel or Plate-Vertex formats to Wavefront OBJ format, use the companion tool PlateVertex2Obj.py.

Usage

Purpose

Convert simple 3D PDS Shapemodel or Plate-Vertex files to Alias WaveFront OBJ format. This assumes original vertices are listed in sequential order (1, 2, 3, 4, …n).

Example: NEAR Eros Shape Model

Download from SBN Tools:

File Format

Input file structure:
Output OBJ format:

Technical Details

Coordinate System

The PLY mesh uses the same coordinate system as the input raster:
  • X, Y: Derived from geotransform (map coordinates)
  • Z: Elevation values from raster band

Mesh Topology

Each grid cell creates two triangles:
Triangles: (a, a+width, a+width+1) and (a, a+width+1, a+1)

Source Code Reference

  • gdal2PLY.py:28-62 - PLY file writing with binary format support
  • gdal2PLY.py:69-78 - Vertex array creation from raster
  • gdal2PLY.py:81-93 - Triangle index generation
  • PlateVertex2Obj.py:38-53 - PDS to OBJ conversion loop

Limitations

  • Does not currently handle NoData values automatically (use workaround)
  • Loads entire raster into memory (may require significant RAM for large DEMs)
  • Output is binary format only (ASCII option exists but not default)
  • No color/texture mapping (geometry only)

See Also